<!DOCTYPE html>
<html>
<head>
    <title>添加收费项目--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../Js/jquery-ui-1.13.0.custom/jquery-ui.css"/>
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
    <script type="text/javascript" src="../Js/webUtil.js"></script>
    <script type="text/javascript" src="../Js/jquery-ui-1.13.0.custom/jquery-ui.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
        $(function () {
            $('#backid').click(function () {
                window.location.href = "charge.html";
            });
        });
    </script>
</head>
<body>
<form class="definewidth m20" onsubmit="return(false);">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">病历号</td>
            <td id="patientId">1103</td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">姓名</td>
            <td id="name">黄飞鸿</td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">收费项目</td>
            <td><input type="text" name="name" value="" autocomplete="off"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">收费金额</td>
            <td><input type="text" name="fee" value="" disabled/></td>
        </tr>
        <tr>
            <td colspan="2">
                <center>
                    <button class="btn btn-primary" type="button" onclick="save()">保存</button>
                    <button class="btn btn-success" name="backid" id="backid">返回列表</button>
                </center>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
<script>
    function save() {
        let url = document.location.toString();
        let behId = url.GetValue("id");
        let chapId = $("input[name='name']").attr("id");
        if (behId == null) {
            alert("未获取到病人ID，请返回重试！");
        } else if (chapId == "") {
            alert("请选择收费项目！");
        } else {
            $.ajax({
                type: "POST",
                url: "/pricePeople/",
                data: "behId=" + behId + "&chapId=" + chapId,
                success: function (vo) {
                    if (vo.code == 200) {
                        alert(vo.obj);
                        window.location.href = "charge2.html"
                    } else
                        alert(vo.msg);
                }
            })
        }
    }

    function loadData() {
        let url = document.location.toString();
        let id = url.GetValue("id");
        if (id == null) {
            alert("非法id!");
        } else {
            $.ajax({
                type: "GET",
                url: "/register/" + id,
                success: function (vo) {
                    if (vo.code == 200) {
                        let obj = vo.obj;
                        $("#patientId").html(obj.id);
                        $("#name").html(obj.name);
                    } else {
                        alert(vo.msg);
                        window.location.href="charge2.html";
                    }

                }
            })
        }
    }

    $(function () {
        loadData();
        $("input[name='name']").autocomplete({
            source: function (req, resp) {
                let term = req.term;
                if (term.trim() != "") {
                    $("input[name='fee']").val("");
                    $("input[name='name']").attr("id","");
                    $.ajax({
                        type: "GET",
                        data: $("form").serialize(),
                        url: "/chargeProject/list",
                        success: function (vo) {
                            let nameList = Array();
                            let list = vo.list;
                            list.forEach(function (obj) {
                                nameList.push({"label": obj.name, "value": obj.id});
                            })
                            resp(nameList);
                        }
                    })
                }
            },
            autoFocus: true,
            select: function (event, ui) {
                let item = ui.item;
                event.preventDefault();
                $("input[name='name']").val(item.label);
                $("input[name='name']").attr("id", item.value);
                $.ajax({
                    type: "GET",
                    url: "/chargeProject/" + item.value,
                    success: function (vo) {
                        if (vo.code == 200) {
                            $("input[name='fee']").val(vo.obj.money);
                        } else {
                            alert(vo.msg);
                            $("input[name='name']").val("");
                        }
                    }
                })
            }
        });
    })
</script>